import { Entity, PrimaryGeneratedColumn, Column, OneToOne, ManyToMany, ManyToOne, JoinColumn } from 'typeorm';
import { EnterpriseEntity } from '../../enterprise/entities/enterprise.entity';
import { DriverEntity } from 'src/modules/driver/entities/driver.entity';
import { BaseEntity } from 'src/common/entitys/base';
import { Exclude } from 'class-transformer';
import { ClientEntity } from 'src/modules/client/entities';

@Entity({ name: 'sys_user', comment: '用户表' })
export class UserEntity extends BaseEntity {
  @PrimaryGeneratedColumn({ name: 'user_id', type: 'int', comment: '用户ID' })
  userId: number;

  @Column({ name: 'nick_name', type: 'varchar', length: 30, comment: '用户昵称' })
  nickName: string;

  @Column({ name: 'avatar', type: 'varchar', comment: '用户头像' })
  avatar: string;

  @Column({ name: 'user_name', type: 'varchar', length: 30, comment: '账号' })
  userName: string;

  @Exclude({ toPlainOnly: true })
  @Column({ name: 'password', type: 'varchar', length: 255, comment: '密码' })
  password: string;

  @Column({ name: 'phonenumber', type: 'varchar', length: 11, nullable: true, comment: '手机号' })
  phonenumber: string;

  @Column({ name: 'email', type: 'varchar', length: 255, nullable: true, comment: '邮箱' })
  email: string | null;

  @Column({ name: 'login_date', type: 'datetime', nullable: true, comment: '最后登录时间' })
  loginDate: Date | null;

  @Column({ name: 'enterprise_id', type: 'char', nullable: true, comment: '企业ID' })
  enterpriseId: string | null;

  @ManyToOne(() => EnterpriseEntity)
  @JoinColumn({ name: 'enterprise_id' })
  enterprise: EnterpriseEntity;

  @OneToOne(() => DriverEntity, (driver) => driver.user)
  driver: DriverEntity;

  @OneToOne(() => ClientEntity, (client) => client.user)
  client: ClientEntity;
}
